<template>
 <div>
   <el-dialog
   title="请登录系统"
   :close-on-press-escape="false"
   :close-on-click-modal="false"
   :show-close="false"
   :visible.sync="dialogVisible"
   width="40%"
   >
     <el-form ref="form" :model="form" label-width="80px">
       <el-form-item label="账号">
         <el-input v-model="form.account"></el-input>
       </el-form-item>

       <el-form-item label="密码">
         <el-input   type="password" v-model="form.password"></el-input>
       </el-form-item>

       <el-form-item label="账户类型">
         <el-radio-group v-model="form.accountType">
           <el-radio label="admin" >管理员</el-radio>
           <el-radio label="dev" >开发者</el-radio>
         </el-radio-group>
       </el-form-item>

       <el-form-item>
         <el-button type="primary" @click="onSubmit">登录</el-button>
         <el-button @click="dialogVisible = false">取消</el-button>
       </el-form-item>

     </el-form>

   </el-dialog>
 </div>
</template>

<script>



import {login} from "@/api/app";

export default {
  name: 'LoginView',
  data() {
    return {
      dialogVisible: true,
      form: {
        account: 'test2',
        password: '123456',
        accountType: 'dev'
      }
    }
  },
  methods: {
    onSubmit() {

      login(this.form)
          .then(response => {
            console.log(response)
            // 提取 code 和 token
          if( response.code==2000){
               const token = response.data.token;
               localStorage.setItem('token', token); // 存储到 localStorage
               this.$router.push("/appInfo") // 跳转到主页
          }
                 })
          .catch(error => {
            console.error('Error:', error);
          });

    }
  }
}
</script>
